!function () {
    layui.config({base: '/layui/lay/modules/'}).use(['upload','laydate',  'form','status','common'], function () {
        //定义
        var $ = layui.jquery,
            form = layui.form,
            upload = layui.upload,
            laydate = layui.laydate,
            layuiSta = layui.status,//自定义状态控件
            common = layui.common;//自定义状态控件

        //启动富文本编辑
        var ueditor ;
        //初始化渲染列表
        layuiSta.initStaMulti("#statusDiv",$('input[name=status]').val(),true);//构建状态
        //初始化表单
        laydate.render({
            elem: '#releaseTime',
            type: 'datetime'
        });
        form.render();

        //清空富文本编辑框
        ueditor = UE.getEditor('ueditorText');
        //玄学加载
        setTimeout(function () {
            ueditor.setContent($("#contentText").text());
        }, 666);
        $('.edui-editor-bottomContainer').hide();

        $('#backRecord').click(function(){
            window.location.href="/recruit/list";
        });
        //自定义验证规则
        form.verify({
            nameLen: [
                /^[\d\D]{0,32}$/
                ,'最多输入32个字'
            ],
            countLen: [
                /^[\d\D]{0,10}$/
                ,'最多输入10个字'
            ],
            count:[
                /^\d*$/
                ,'只能输入非负的整数'
            ],
            yearLen:[
                /^[\d\D]{0,16}$/
                ,'最多输入16个字'
            ],
            addrLen:[
                /^[\d\D]{0,128}$/
                ,'最多输入128个字'
            ],
        });

        //监听提交事件
        form.on('submit(editRecord)',function(data){

            //获取富文本编辑内容
            var recruitText = ueditor.getContent();
            data.field['recruitText']=recruitText;

            var postUrl = !data.field['id'] ? '/recruit/addRecruit' : '/recruit/editRecruit';

            $.ajax({
                async: false, type: 'post',
                traditional: true,
                data: JSON.stringify(data.field),
                contentType:"application/json;charset=UTF-8",
                processData:false,
                url: postUrl,
                success: function (data) {
                    if (data && data.code == 200) {
                        layer.closeAll();
                        layer.alert('操作成功！', {icon: 1, title: '提示',yes:function(){
                                window.location.href="/recruit/list";
                            }});
                    } else
                        layer.alert(data.msg || '操作失败了！', {icon: 5, title: '提示'});
                },
                error: function () {
                    layer.closeAll();
                    layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
                }
            });
            return false;
        });
    });
}();